import React from 'react';
import Taro from '@tarojs/taro';
import {connect} from 'react-redux';
import {View, Button, Image} from '@tarojs/components';
import {AtModal, AtModalContent, AtBadge} from 'taro-ui';

import * as T from '../../types';
import actions from '../../actions/index';
import {store2Props} from '../../selectors';
// import {OSS_PATH_PREFIX, OSS_BASE_PATH_PREFIX, GAME_RPICE_TYPE, CODE_SUCCESS,CODE_COIN_INSUFFICIENT} from '../../constant';

type IInfoProps = T.IProps & T.IInfoProps;

import './ExchangeResultModal.less';
import 'taro-ui/dist/style/components/modal.scss';
import 'taro-ui/dist/style/components/flex.scss';
import className from 'classnames';
// @ts-ignore

// @ts-ignore
@connect<Partial<IInfoProps>, T.IInfoState>(store2Props, actions)
/**
 * 兑换结果模态框
 */
export default class ExchangeResultModal extends React.Component<Partial<IInfoProps>, T.IInfoState> {
  // 使用state值
  constructor(props) {
    super(props);
    this.state = {
      OPERATES: [
        {
          label: '取消',
          func: 'handleCancel',
          className: 'leftBtn',
        },
        {
          label: '去获取',
          func: 'handleTasks',
          className: 'rightBtn',
        },
      ],
      atModal: {
        closeOnClickOverlay: false,
      },
    };
  }

  /**
   * 渲染
   * @returns
   */
  render() {
    const {
      visible,
      item,
      navbarSettings,
    } = this.props;
    const {atModal, OPERATES} = this.state;

    console.log('exchangeModal render item', item);

    let operates = [OPERATES[0], OPERATES[1]];

    return (
      <AtModal
        isOpened={visible}
        className="exchangeModal"
        closeOnClickOverlay={atModal.closeOnClickOverlay}
        atModalStyle={{top: navbarSettings.navBarHeight}}
      >
        <AtModalContent>
          <View className="modalContent">
            <View className="exchangeModalContent">
              {this.renderExchangeResult()}
            </View>
            <View className="modalFooter">
              {operates.map((i: any, index: number) => (
                <View key={'operate' + index} className={i.className}>
                  <Button onClick={() => this[i.func](i)} className={i.className + 'Button'}>
                    {i.label}
                  </Button>
                </View>
              ))}
            </View>
          </View>
        </AtModalContent>
      </AtModal>
    );
  }

  /**
   * 点击取消
   */
  handleCancel = () => {
    this.props.onCancel();
  };

  /**
   * 去获取处理
   */
  handleTasks = () => {
    this.props.onTask();
  };



  /**
   * 兑换结果页面
   */
  renderExchangeResult() {
    return (
      <View className="extraResultError">
        <View>很抱歉&nbsp; 魔力豆不足</View>
        <View>兑换失败</View>
      </View>
    );
  }
}
